package com.anita.member.domain.model.member;

import com.anita.member.common.exception.BusinessException;

/**
 * 用户名值对象
 * @author qiu
 * @date 2025/10/17
 * @description
 */
public record Username(String value){

    public Username {
        if(value == null || value.trim().isEmpty()){
            throw new BusinessException("会员用户名不能为空");
        }
        if(value.length() < 4 || value.length() > 20){
            throw new BusinessException("会员用户名长度必须在4-20个字符之间");
        }
    }

    public static Username of(String s) {
        String trimmed = s==null? null : s.trim();
        return new Username(trimmed);
    }

    public String getValue() {
        return value;
    }
}
